#if !defined(_SSTRUCT_H)
#define _SSTRUCT_H

#include "SComplexValue.h"
#include "SStructTypeDescriptor.h"
#include <boost/regex.hpp>
#include <map>

CREATE_ALIAS( SStruct );

/**
 * Class used to store a struct variable.
 */
class DECLARATION_DLL SStruct : public SComplexValue
{
	/** Map use to store the struct members values. */
	SValueSpMap values;

	/** The type descriptor. */
	SStructTypeDescriptorSp typeDescriptor;

	/**
	 * Create a SStruct variable.
	 */
	SStruct(SStructTypeDescriptorSp typeDescriptor)
	{
		this->typeDescriptor = typeDescriptor;
	}

	public:

		/**
		 *   Get the variable type.
		 */
		virtual SType GetType() const
		{
			return STypeStruct;
		}

		/**
 		 * Return the number of members.
		 */
		virtual int GetNumberOfMembers()
		{
			return typeDescriptor->GetNumberOfMembers();
		}

		/**
		 * Returns a map with all the member value inside.
		 */
		virtual SValueSpMapSp GetAllMembersAsMap();

		/**
		 *   Get the type descriptor.
		 */
		virtual TypeDescriptorSp GetTypeDescriptor()
		{
			return typeDescriptor;
		}

		/**
		 * Set a member of the struct by position.
		 */
		virtual void Set(int index, SValueSp value);

		/**
		 * Set a member of the struct with a specific name.
		 */
		virtual void Set(string memberName, SValueSp value);

		/**
		 * Get the value of a member by index.
		 */
		virtual SValueSp Get(int index);

		/**
		 * Get the value of a member with a specific name.
		 */
		virtual SValueSp Get(string memberName);

		/**
		 * Get the value of a member by index and try to cast it.
		 */
		template <typename T>
		shared_ptr<T> Get(int index)
		{
			return Get(index)->As<T>();
		}

		/**
		 * Get the value of a member with a specific name and try to cast it.
		 */
		template <typename T>
		shared_ptr<T> Get(string memberName)
		{
			return Get(memberName)->As<T>();
		}

		/**
		 * Returns true if the member with a specific name is set.
		 * Is possible that a member has not a value.
		 */
		virtual bool IsSet(string memberName);
		
		/**
 		 * Returns true if all the members are set.
		 */
		virtual bool IsAllMemberSet();

		/**
		 * Returns a string representation of the value.
		 */
		virtual string ToString() 
		{ 
			return SComplexValue::ToString(); 
		}

		/**
		 * Returns a string representation of the value in a specific format.
		 */
		virtual string ToString(string format);

		/**
		 *   Factory method to create a SStruct variable.
		 */
		static SStructSp Create(SStructTypeDescriptorSp typeDescriptor);

		/**
		 *   Factory method to create a SStruct variable from a string.
		 */
		static SStructSp Parse(SStructTypeDescriptorSp typeDescriptor, string s);
		static SStructSp Parse(SStructTypeDescriptorSp typeDescriptor, string s, SValueSpMapSp vars);

};

#endif  //_SSTRUCT_H
